/*********************************************************************************
 *      Copyright:  (C) 2020 Juan
 *                  All rights reserved.
 *
 *       Filename:  unpack_json.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(12/07/20)
 *         Author:  wangruijie <1046299465@qq.com>
 *      ChangeLog:  1, Release initial version on "12/07/20 14:50:13"
 *                 
 ********************************************************************************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include"cJSON.h"

int main(int argc, char **argv)
{

    cJSON *tnode = NULL;
    char *string = "{\"Mobile\":[\"18585761500\"], \"中文短信\":[\"你好\"], \"English_SMS\":[\"hello\"]}";
    cJSON *json = cJSON_Parse(string);
    cJSON *node = NULL;

    node = cJSON_GetObjectItem(json,"Mobile");
    if(node == NULL)
    {
        printf("Mobile node == NULL\n");
        return -1;
    }

    if(1 != cJSON_HasObjectItem(json,"Mobile"))
    {
        printf("not found Mobile node\n");
        return -1;
    }

    cJSON_ArrayForEach(tnode,node)
    {
        if(tnode->type == cJSON_String)
        {
            printf("The mobile is:%s\n",tnode->valuestring);   
        }
        else
        {
            printf("node's type is not string\n");
        }
    }

    node = cJSON_GetObjectItem(json,"中文短信");
    if(node == NULL)
    {
        printf("中文短信 node is NULL\n");
        return -2;
    }

    if(1 != cJSON_HasObjectItem(json,"中文短信"))
    {
        printf("not found 中文短信 node\n");
        return -3;
    }

    cJSON_ArrayForEach(tnode,node)
    {
        if(tnode->type == cJSON_String)
        {
            printf("The 中文短信 is:%s\n",tnode->valuestring);
        }
        else
        {
            printf("node's type is not string\n");
            return -4;
        }
    }

    node = cJSON_GetObjectItem(json,"English_SMS");
    if(node == NULL)
    {
        printf("English_SMS node is NULL\n");
        return -5;
    }

    if(1 != cJSON_HasObjectItem(json,"English_SMS"))
    {
        printf("not found English_SMS node\n");
        return -6;
    }

    cJSON_ArrayForEach(tnode,node)
    {
        if(tnode->type == cJSON_String)
        {
            printf("The English_SMS is:%s\n",tnode->valuestring);
        }
        else
        {
            printf("node's type is not string\n");
            return -4;
        }
    }

    return 0;
}
